import Vue from 'vue'
// 0. 引入路由模块
import VueRouter from 'vue-router'
import Home from '../views/home/index.vue'
import FooterNav from '@/components/FooterNav.vue'

// 1. 注册路由模块
Vue.use(VueRouter)

// 2. 定义路由对象
const routes = [
  // {
  //   path: '/home',
  //   redirect: '/'
  // },
  {
    path: '/',
    name: 'Home',
    alias: '/home',
    components: {
      default: Home,
      foot: FooterNav
    }
  },
  {
    path: '/kind',
    name: 'Kind',
    components: {
      default: () => import(/* webpackChunkName: "kind" */ '../views/kind/index.vue'),
      foot: FooterNav
    }
  }, {
    path: '/cart',
    name: 'Cart',
    components: {
      default: () => import(/* webpackChunkName: "pro" */ '../views/cart/index.vue')
    }
  }, {
    path: '/my',
    name: 'My',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/my/index.vue'),
      foot: FooterNav
    }
    // // 单个路由守卫
    // beforeEnter: (to, from, next) => {
    //   if (sessionStorage.getItem('isLogin') === 'ok') {
    //     next()
    //   } else {
    //     next('/login?from=my')
    //   }
    // }
  }, {
    // path: '/detail/:id/pass/:qwe',
    // '/detail/ahjystfa7e5123j'
    // this.$route.params
    // this.$route.params
    path: '/detail/:id',
    name: 'abc',
    components: {
      default: () => import(/* webpackChunkName: "pro" */ '../views/detail/index.vue')
    },
    props: {
      default: true
    }
  }, {
    path: '/register',
    name: 'Register',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/register/index.vue')
    }
  }, {
    path: '/login',
    name: 'Login',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/login/index.vue')
    }
  }, {
    path: '/order',
    name: 'Order',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/order/index.vue')
    }
  }, {
    path: '/search/:s',
    name: 'Search',
    components: {
      default: () => import(/* webpackChunkName: "search" */ '../views/search/index.vue')
    },
    props: true
  }, {
    path: '/searchRes/:s/type/:t',
    name: 'SearchRes',
    components: {
      default: () => import(/* webpackChunkName: "search" */ '../views/searchRes/index.vue')
    },
    props: {
      default: true
    }
  }, {
    path: '/setting',
    name: 'Setting',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/setting/index.vue')
    }
  }, {
    path: '/material',
    name: 'Material',
    components: {
      default: () => import(/* webpackChunkName: "user" */ '../views/material/index.vue')
    }
  }
]

// 3. 创建路由,设置路由对象
const router = new VueRouter({
  routes
})

// 全局路由守卫(所有)
// router.beforeEach((to, from, next) => {
//   if (sessionStorage.getItem('isLogin') === 'ok' || to.name === 'Login' || to.name === 'Register') {
//     next()
//   } else {
//     next('/login')
//   }
// })

export default router
